<?php

class ActionChangeProfile extends Action {
	public function IsPermitted(){ return !User::GetCurrent()->IsVisitor(); }
	public function GetIconName(){ return 'oxy/ico/User'; }


	public function Render(){
		
		$x = clone User::GetCurrent();
		$ui = $x->GetUIObject();
		
		$v = new ValidatorSet();		
		if ($this->IsPostback()){
			$ui->Read(Http::$POST);

			$xx = User::RetrieveByUsername($x->Username);

			$v->Username->CheckMandatory($x->Username);
			$v->Username->Check($xx==null || $xx->id->AsInt()==$x->id->AsInt(), Lemma::ErrorUsernameExists());

			if ($v->HasPassed()){
				$x->Save();
				User::GetCurrent()->Load();
				echo '<br/>';
				echo new SuccessMessage(Lemma::MessageProfileChanged());
				return;
			}
		}			
			
		
		
		echo $this->GetForm();
		$z = FieldTableControl::Make()->WithWidth('100%');
		$z->Add(TextboxControl::Make($ui->Username))->WithValidator($v->Username);
		$z->Add(TextboxControl::Make($ui->Email));
		$z->AddOKCancel();
		$z->Render();
		echo $this->EndForm();
		
		
		
		
	}
}

?>
